
import cloud from '@lafjs/cloud'
import nw from "nw-lafjs";
import {fail, ok} from "@/utils/responseUtil";

const db = cloud.database()
const _ = db.command

export default async function (ctx: FunctionContext) {
  let  body = ctx.body
  /**
   * {
   *    "_id":"dsdd",
   * }
   */
  //1.校验参数
  if (nw.util.isNull(body._id)){
    return fail("参数不合法")
  }

  //2.查询用户
  let user = await nw.db.findByWhereJson({
    dbName:"admin",
    whereJson:{
      _id:_.eq(body._id)
    }
  })

  if (nw.util.isNull(user)){
    return  fail("用户名或者密码不正确")
  }

  return ok(nw.util.deleteObjectKeys(user,["phone","wareId","deleted","token","loginTime"]),"查询成功")
}
